package cn.wilson.hrm.service.impl;

import cn.wilson.hrm.domain.Course;
import cn.wilson.hrm.domain.CourseResource;
import cn.wilson.hrm.dto.CourseResourceSaveDTO;
import cn.wilson.hrm.mapper.CourseResourceMapper;
import cn.wilson.hrm.service.ICourseResourceService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wilson.liu
 * @since 2020-04-21
 */
@Service
public class CourseResourceServiceImpl extends ServiceImpl<CourseResourceMapper, CourseResource> implements ICourseResourceService {




    @Override
    public void saveOrUpdate(CourseResourceSaveDTO courseResourceSaveDTO) {
        //获取课程对象
        Course course = courseResourceSaveDTO.getCourse();

        //通过课程获取到id   判断参数
        if (course.getId() == null){
            throw new IllegalArgumentException("未选择所属课程");
        }

        //保存资源  resource
        CourseResource courseResource = courseResourceSaveDTO.getCourseResource();
        //保持一对一
        courseResource.setId(course.getId());
        //设置图片资源
        courseResource.setCourseId(course.getId());
        courseResource.setResources(courseResource.getResources());
        //保存
        baseMapper.insert(courseResource);
    }
}
